package com.zzyl.controller;


import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponse;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponse;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("iot")
@Api(tags = "智能检测")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation(value = "同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "获取产品列表")
    public ResponseResult allProduct() {
        List<ProductVo> list = deviceService.allProduct();
        return success(list);
    }

    @PostMapping("RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult insert(@RequestBody DeviceDto deviceDto) {
        deviceService.insert(deviceDto);
        return success();
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备")
    public ResponseResult pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        PageResponse pageResponse  =deviceService.pageQueryDevice(devicePageQueryDto);
        return success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详情")
    public ResponseResult queryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        DeviceVo deviceVo =deviceService.queryDeviceDetail(deviceDto);
        return success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询设备物模型数据")
    public ResponseResult queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        QueryDevicePropertyStatusResponse response = deviceService.queryDevicePropertyStatus(deviceDto);
        return success(response.getBody().getData());
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查询指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryThingModelPublished(@RequestBody DeviceDto deviceDto) {
        QueryThingModelPublishedResponse response = deviceService.queryThingModelPublished(deviceDto);
        return success(response.getBody().getData());
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备名称")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return success();
    }

    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.deleteDevice(deviceDto);
        return success();
    }

}
